package com.lyz.dataStructure.algorithm.小米2020;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 20:04
 * @Description:
 **/

import java.util.Scanner;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/9/11 20:04
 *@Description:
 **/
public class 最大利润化1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] st = s.split(" ");
        long[] arr = new long[st.length];
        for(int i =0;i<arr.length;i++){
            arr[i] = Integer.parseInt(st[i]);
        }
        System.out.println(maxProfit(arr)-2);
    }

    static  long  maxProfit(long[] prices) {
        // write your code here
        //这里应该是有利润就要出手
        if(prices.length<2)return 0;
        long low = prices[0];
        long profit = 0;
        for(int i=1;i!=prices.length;++i){
            if(prices[i]>low){
                profit = profit+prices[i]-low;
            }
            low = prices[i];
        }
        return profit;
    }
}
